package com.ynet.middleground.mobile.approve.mq.producer;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHeaders;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Component;

import com.ynet.core.log.IfpLogger;
import com.ynet.middleground.mobile.approve.mq.SourceMobileApprove;

/**
 * 测试 MQ 专用
 * 
 * @author liulx
 */
@EnableBinding({SourceMobileApprove.class})
@Component
public class SourceProducerBackupPlan {

    @Autowired
    private SourceMobileApprove source;

    /**
     * 手动补偿专用，模拟渠道往 MQ 推送消息
     *
     * @param msg 推送消息内容
     */
    public void sendApproveStateMessages(Map<String, Object> msg) {
        IfpLogger.info("mq", "注意: 手动补偿，模拟核心业务系统主动向移动审批推送审批结果信息同步数据，往 Binding-{} 推送信息-{}",
            SourceMobileApprove.BLXD_TO_JKZTYDSP_QDSPJGXX, msg);
        Map<String, Object> headers = new HashMap<>(4);
        // tags 标签对应合约中心 yml 配置文件
        headers.put("TAGS", "in");
        MessageHeaders messageHeaders = new MessageHeaders(headers);
        Message<Map<String, Object>> message = MessageBuilder.createMessage(msg, messageHeaders);
        this.source.receiveChannelApproveStateManualCompensation().send(message);
    }

}
